package com.whcoding.exception.handler.controller;


import com.whcoding.exception.handler.constant.ResultStatus;
import com.whcoding.exception.handler.exception.JsonException;
import com.whcoding.exception.handler.exception.PageException;
import com.whcoding.exception.handler.exception.RunException;
import com.whcoding.exception.handler.model.ApiResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 测试Controller
 * </p>
 *
 * @author: SnailThink
 * @create: 2022-02-24 17:00
 */
@Controller
public class TestController {

	/**
	 * http://localhost:9290/demo/json
	 *
	 * JSON 异常
	 *
	 * @return
	 */
	@GetMapping("/json")
	@ResponseBody
	public ApiResponse jsonException() {
		throw new JsonException(ResultStatus.UNKNOWN_ERROR);
	}

	/**
	 * 运行异常
	 *
	 * @return
	 */
	@GetMapping("/run")
	@ResponseBody
	public ApiResponse runException() {
//		throw new RunException(ResultStatus.UNKNOWN_EXCEPTION);
//		throw new RunException(ResultStatus.UNKNOWN_EXCEPTION.getCode(),
//				ResultStatus.UNKNOWN_EXCEPTION.getMessage());
		throw new RunException(ResultStatus.UNKNOWN_EXCEPTION);
	}

	/**
	 * 页面异常
	 *
	 * @return
	 */
	@GetMapping("/page")
	public ModelAndView pageException() {
		throw new PageException(ResultStatus.UNKNOWN_ERROR);
	}
}
